Ending a Session
Ending a Session
After data is written and read in, use the PPCEnd function to end the session
(identified by the session reference number). You may receive an error if you
use the PPCEnd function to end a session that has already been terminated.
The following program illustrates how you use the PPCEnd function to end a
session.
// Ending a PPC session using the PPCEnd function
// Assuming inclusion of MacHeaders
#include <PPCToolBox.h>
// Prototype your end function like this prior to calling it
OSErr MyPPCEnd(PPCSessRefNum);
OSErr MyPPCEnd(PPCSessRefNum theSessRefNum)
{
PPCEndPBRec thePPCEndPBRec;
// Set the Session ref number to pass to PPCEnd
thePPCEndPBRec.sessRefNum = theSessRefNum;
// Return result of PPCEnd
return PPCEnd(&thePPCEndPBRec, FALSE); // synchronous
}
The PPCEnd function causes all calls to the PPCRead and PPCWrite
functions to complete (with a sessClosedErr result code) and invalidates the
session reference number. The PPCEnd function also releases any
PPC Toolbox resources so that they can be reused.
Use the PPCClose function to close the port specified by the port reference
number. When you close a port, all sessions associated with a port are ended.
Any active asynchronous calls associated with a session then call their
completion routines (if they have one).
The following program illustrates how you use the PPCClose function to
close a port.
// Closing a PPC port using the PPCClose function
// Assuming inclusion of MacHeaders
#include <PPCToolBox.h>
// Prototype your PPCClose routine like this prior to calling it
OSErr MyPPCClose (PPCPortRefNum);
OSErr MyPPCClose(PPCPortRefNum thePortRefNum)
{
PPCClosePBRec theClosePBRec;
// Set the proper portRefNum, which is grabbed from PPCOpen function
theClosePBRec.portRefNum = thePortRefNum;
return PPCClose(&theClosePBRec, FALSE); // synchronous
}
In this example, the call to PPCClose is made synchronously.